package me.keiwu.user.dao;

import me.keiwu.user.domain.TotalStepMark;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by kei on 14/12/2017.
 */
public interface TotalStepMarkDao extends CrudRepository<TotalStepMark, Integer> {

    Integer countByUserIdAndDays(Long userId, Integer days);


    @Query(value = "select days from total_step_mark where user_id=?1 and days in (?2)", nativeQuery = true)
    List<Integer> findAllByUserIdAndDaysList(Long userId, List<Integer> daysList);


    @Modifying
    @Query(value = "delete from total_step_mark where user_id=?1 and days<?2", nativeQuery = true)
    void clean(Long userId, Integer beforeDays);

}
